<?php

/**
 * @author 
 * @copyright 2009
 */
$secured = array(1 => 'com_content', 'com_categories', 'com_comment', 'com_user');
$components = dirlist('../components/');

if(!empty($_GET['file'])){
	if(!in_array(strtolower($_GET['file']), $secured)){
		
	$log->write(8, 'com_install', 'NOW()', 'User has deleted component '.$_GET['file'], $_SESSION['id']);
		
	define('COM_INSTALL', true);
	if(is_file('../components/'.$_GET['file'].'/uninstall.php')){
		require_once('../components/'.$_GET['file'].'/uninstall.php');
	}
	
	$_GET['file'] = str_replace("/", " ", $_GET['file']);
	$_GET['file'] = str_replace("../", " ", $_GET['file']);
	$_GET['file'] = str_replace("..", " ", $_GET['file']);
	rmdirr('../components/'.$_GET['file']);

	echo '<p class="msg done">'.Lang::getBackGlobal('install_delete_done').'</p>';
	echo '<meta http-equiv="refresh" content="4;url=index.php?p=install&type=del_com">';
	}else{
		echo '<p class="msg error">'.Lang::getBackGlobal('install_delete_component_protected').'</p>';
	}
}
$i = 1;
echo '<table>';
echo "\n<tr><th>#</th><th>Komponenta</th><th>Verze</th><th>Autor</th><th>Akce</th></tr>\n";

foreach($components as $key){
	
	if(is_file('..'.DIR_SEP.'components'.DIR_SEP.$key.DIR_SEP.'info.xml')){

    $xml = simplexml_load_file('..'.DIR_SEP.'components'.DIR_SEP.$key.DIR_SEP.'info.xml');
    $author = (string)$xml->info[0]->author;
    $version = (string)$xml->info[0]->version;

	}else{
		$author = 'unknown';
		$version = 'unknown';
	}
	if(!in_array(strtolower($key), $secured)){
		$action = '<a href="#" onclick="javascript:confirm_uninstall(\''.$key.'\', \'index.php?p=install&type=del_com&file='.$key.'\');return false;">'.Lang::getBackGlobal('install_delete').'</a>';
	}else{
		$action = '<em>'.Lang::getBackGlobal('install_delete_protected').'</em>';
	}
	
	echo '<tr><td>'.$i.'</td><td>'.$key.'</td><td>'.$version.'</td><td>'.$author.'</td><td>'.$action.'</td></tr>';
	$i++;
}
echo "\n</table>";
?>